package com.yuxi.al.leercode;

/**
 * //一个有序数组1,1,2,2,3,3,4,4,5,6,6,7,7,8,8找出只出现一次的元素
 * Created by yuxi on 17/2/5.
 */
public class ArrFindOne {
    public static void main(String[] args) {
        int arr[] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8};
        int result = findOne(arr);
        System.out.println(result);
    }

    private static int findOne(int[] arr) {
        if (arr.length < 0 || arr == null) {
            return -1;
        }
        //由于亦或特性,相同为0 相异为1
        int tmp = arr[0];
        for (int i = 1; i < arr.length; i++) {
            tmp = tmp ^ arr[i];
        }
        return tmp;
    }
}
